package com.ruoyi.teaching.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teaching.mapper.YaCourseDesignDetailMapper;
import com.ruoyi.teaching.domain.YaCourseDesignDetail;
import com.ruoyi.teaching.service.IYaCourseDesignDetailService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 课程设计详情Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-15
 */
@Service
public class YaCourseDesignDetailServiceImpl extends ServiceImpl<YaCourseDesignDetailMapper, YaCourseDesignDetail> implements IYaCourseDesignDetailService
{
    @Autowired
    private YaCourseDesignDetailMapper yaCourseDesignDetailMapper;

    /**
     * 查询课程设计详情
     * 
     * @param id 课程设计详情主键
     * @return 课程设计详情
     */
    @Override
    public YaCourseDesignDetail selectYaCourseDesignDetailById(Long id)
    {
        return yaCourseDesignDetailMapper.selectYaCourseDesignDetailById(id);
    }

    /**
     * 查询课程设计详情列表
     * 
     * @param yaCourseDesignDetail 课程设计详情
     * @return 课程设计详情
     */
    @Override
    public List<YaCourseDesignDetail> selectYaCourseDesignDetailList(YaCourseDesignDetail yaCourseDesignDetail)
    {
        return yaCourseDesignDetailMapper.selectYaCourseDesignDetailList(yaCourseDesignDetail);
    }

    /**
     * 新增课程设计详情
     * 
     * @param yaCourseDesignDetail 课程设计详情
     * @return 结果
     */
    @Override
    public int insertYaCourseDesignDetail(YaCourseDesignDetail yaCourseDesignDetail)
    {
        yaCourseDesignDetail.setCreateTime(DateUtils.getNowDate());
        return yaCourseDesignDetailMapper.insertYaCourseDesignDetail(yaCourseDesignDetail);
    }

    /**
     * 修改课程设计详情
     * 
     * @param yaCourseDesignDetail 课程设计详情
     * @return 结果
     */
    @Override
    public int updateYaCourseDesignDetail(YaCourseDesignDetail yaCourseDesignDetail)
    {
        yaCourseDesignDetail.setUpdateTime(DateUtils.getNowDate());
        return yaCourseDesignDetailMapper.updateYaCourseDesignDetail(yaCourseDesignDetail);
    }

    /**
     * 批量删除课程设计详情
     * 
     * @param ids 需要删除的课程设计详情主键
     * @return 结果
     */
    @Override
    public int deleteYaCourseDesignDetailByIds(Long[] ids)
    {
        return yaCourseDesignDetailMapper.deleteYaCourseDesignDetailByIds(ids);
    }

    /**
     * 删除课程设计详情信息
     * 
     * @param id 课程设计详情主键
     * @return 结果
     */
    @Override
    public int deleteYaCourseDesignDetailById(Long id)
    {
        return yaCourseDesignDetailMapper.deleteYaCourseDesignDetailById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int editRelatedInterview(Integer cdId, List<Integer> interviewIdList) {
        //1.删除该课程的所有关联面试题
        yaCourseDesignDetailMapper.deleteRelatedInterview(cdId);
        //2.批量新增中间表
        interviewIdList.forEach(interviewId->{
            yaCourseDesignDetailMapper.insertCourseDesignInterview(cdId,interviewId);
        });
        return 1;
    }
}
